/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mwt.xml.xdbforms.dblayer.query.impl;

import java.util.ArrayList;
import java.util.List;
import mwt.xml.xdbforms.dblayer.query.Projections;

/**
 * Progetto Master Web Technology
 * @author Gianfranco Murador, Cristian Castiglia, Matteo Ferri
 *
 * Classe statica per la definizione di
 * colonne della tabella sulla quale fare
 * la proiezione.. 
 *
 */
public class ProjectionsImpl implements Projections{

    private List<String> proList = new ArrayList<String>();
    private StringBuilder sqlStatement;

    public void property(String name) {
        proList.add(name);
    }

    public void setDistinct(String name) {

        for (int i = 0; i < proList.size(); i++) {
            String colname = proList.get(i);

            if (colname.equals("name")) {
                colname = "DISTINCT " + name;
                proList.set(i, colname);
                break;
            }

        }

    }

    public String toSqlString() {

        sqlStatement = new StringBuilder(proList.toString());
        sqlStatement.deleteCharAt(0);
        sqlStatement.deleteCharAt(sqlStatement.length() - 1);
        return sqlStatement.toString();

    }
}
